package com.lgmshare.component.storage;

import android.content.Context;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author lim
 * @description: TODO
 * @email lgmshare@gmail.com
 * @datetime 2017/12/7 10:17
 */
class FileHelper {

    public static FileHelper getInstance(Context context) {
        return new FileHelper(context);
    }

    public FileHelper(Context context) {
    }

    public void write(String uri, String data) throws IOException {
        byte[] bytes = data.getBytes();
        FileOutputStream os = null;
        try {
            File file = new File(uri);
            if (file.exists()) {
                file.delete();
            }
            file.createNewFile();
            os = new FileOutputStream(uri);
            os.write(bytes);
            os.flush();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != os) {
                os.close();
            }
        }
    }
}
